#ifndef _DOUBLELINKLIST_H_
#define _DOUBLELINKLIST_H_

#include <iostream>
#include <stddef.h>
//#include "DynamicArray.h"

class DoubleLinkList
{
public:
    using ElementType = void*;

    size_t Size()
    {
        return size;
    }

    void SetFreeFunc(void (*Free)(ElementType))
    {
        this->Free=Free;
    }

    void SetPrintFunc(void (*Print)(ElementType))
    {
        this->Print=Print;
    }

    void SetCompareFunc(int (*Compare)(ElementType,ElementType))
    {
        this->Compare = Compare;
    }


    void SetCopyFunc(ElementType (*Copy)(ElementType))
    {
        this->Copy=Copy;
    }

    DoubleLinkList();
    ~DoubleLinkList();
    DoubleLinkList(const DoubleLinkList &list);
    DoubleLinkList operator=(const DoubleLinkList &list);
    //尾插
    void InsertTail(const ElementType& element);
    void InsertByIndex(size_t index,const ElementType& element);
    //删除 2
    void RemoveByIndex(size_t index);
    void RemoveByElement(const ElementType& element);
    //查找 2
    DoubleLinkList::ElementType* FindByIndex(size_t index);
    
    // DARRAY::DynamicArray FindeByElement(const DoubleLinkList::ElementType& element);

    //修改 2
   
    void UpdateByIndex(size_t index,const DoubleLinkList::ElementType &element);
    
    void UpdateByElement(DoubleLinkList::ElementType& oldvalue,DoubleLinkList::ElementType& newvalue);
    //排序 快排
    void Sort();

    //交并补

    void show();
private:
    
    struct Node
    {
        Node(const ElementType &value)
        {
            this->value = value;
            next = prev = nullptr;
        }
        ElementType value;
        Node *next;
        Node *prev;
    };

    Node *head;
    Node *tail;
    size_t size;
    // 释放对象的函数指针
    void (*Free)(void *);
    // 比较大小的指针
    int (*Compare)(void *, void *);
    // 打印数据的指针
    void (*Print)(ElementType);
    void FastSort(Node *start,Node* end);
    ElementType (*Copy)(ElementType);
};

#endif